package com.huffman.smart_picture.domain.vo.pircture;

import cn.hutool.json.JSONUtil;
import com.huffman.smart_picture.domain.entity.Picture;
import lombok.Data;

import java.util.List;

/**
 * @author DengLin
 * @date 2025/1/22 20:03
 * @description: 瀑布流vo
 */
@Data
public class WaterfallPictureVo {
    /**
     * id
     */
    private Long id;

    /**
     * 图片 url
     */
    private String url;

    /**
     * 压缩图片 url
     */
    private String compressUrl;

    /**
     * 缩略图片 url
     */
    private String thumbnailUrl;

    /**
     * 图片名称
     */
    private String picName;

    /**
     * 分类
     */
    private String category;

    /**
     * 标签（JSON 数组）
     */
    private List<String> tags;

    /**
     * 作者名
     */
    private String author;
    /**
     * 作者头像
     */
    private String avatar;

    /**
     * 当前用户是否点赞
     */
    private Boolean isFavorite = false;

    public static WaterfallPictureVo convert(Picture picture){
        WaterfallPictureVo waterfallPictureVo = new WaterfallPictureVo();
        waterfallPictureVo.setId(picture.getId());
        waterfallPictureVo.setUrl(picture.getUrl());
        waterfallPictureVo.setCompressUrl(picture.getCompressUrl());
        waterfallPictureVo.setThumbnailUrl(picture.getThumbnailUrl());
        waterfallPictureVo.setPicName(picture.getPicName());
        waterfallPictureVo.setCategory(picture.getCategory());
        // 类型不同，需要转换
        waterfallPictureVo.setTags(JSONUtil.toList(picture.getTags(), String.class));
        return waterfallPictureVo;
    }
}
